<template>
  <div class="export-avdice">
    <div class="list_item">
      <div class="list_l">
        <img src="../../../assets/images/online-consulting.png" alt="" />
        <div class="text">
          在线咨询(
          <div style="display: inline; color: #fd5151">
            {{ expertP.consultPrice }}元
          </div>
          )
        </div>
      </div>

      <Button
        type="error"
        @click="askDoctor()"
        shape="circle"
        :disabled="expertP.consultOpen != 1"
      >
        开始咨询
        <Icon type="ios-arrow-forward" />
      </Button>
    </div>

    <div class="list_item">
      <div class="list_l">
        <img src="../../../assets/images/booking-register.png" alt="" />
        <div class="text">
          前往预约(
          <div style="display: inline; color: #fd5151">
            {{ expertP.registerPrice }}元
          </div>
          )
        </div>
      </div>

      <Button
        type="error"
        @click="toAppointment"
        shape="circle"
        :disabled="expertP.registerOpen != 1"
      >
        前往预约
        <Icon type="ios-arrow-forward" />
      </Button>
    </div>

    <!-- 患者评价 -->
    <div class="evaluate">
      <div class="title">
        <div class="image"></div>
        <div class="text">患者评价({{ total }})</div>
      </div>
      <List class="parent-box">
        <ListItem v-for="(item, index) in evaluateList" :key="index">
          <ListItemMeta
            :avatar="
              item.member.face
                ? item.member.face
                : '../../../assets/images/default_avatar.png'
            "
            :title="item.member.nickName"
            :description="item.userEvaluateTime"
          />
          <template slot="extra">
            <div class="list-item">
              <div class="text">
                <p class="grade">
                  <span
                    style="
                      font-size: 12px;
                      font-weight: bold;
                      padding-right: 5px;
                    "
                    >{{ item.grade }}</span
                  >
                  <Rate disabled :value="item.grade" />
                </p>
                <p class="desc" v-html="item.userEvaluate"></p>
              </div>

              <div class="child-box" v-if="item.expertReply">
                <div class="child-item">
                  <p>医生回复</p>
                  <p>{{ item.expertReply || "暂无" }}</p>
                  <p>{{ item.expertReplyTime || "暂无" }}</p>
                </div>
              </div>
            </div>
          </template>
        </ListItem>
      </List>
      <empty v-if="evaluateList.length === 0" />
    </div>
  </div>
</template>
<script>
import { getEvaluatelist } from "@/api/myAttention";
import LoginVue from "../../Login.vue";
export default {
  props: {
    expertP: Object,
  },
  data() {
    return {
      total: "",
      params: {
        page: 1,
        rows: 5,
        expertId: this.$route.query.id,
      },
      evaluateList: [],
    };
  },
  mounted() {
    this.getList();
    console.log(this.expertP);
  },
  methods: {
    //开始咨询
    askDoctor(item) {
      localStorage.setItem("consultPrice", this.expertP.consultPrice);
      this.$router.push({
        path: "/start",
        query: {
          expertName: this.expertP.realName,
          expertId: this.expertP.id,
        },
      });
    },
    // 前往预约
    toAppointment() {
      let data = {
        siteId: "",
        expertId: this.params.expertId,
        realName: this.expertP.realName,
        siteName: "",
        type: "experts", //专家
      };
      localStorage.setItem("realName", this.expertP.realName);
      localStorage.setItem("expertId", this.expertP.id);
      localStorage.setItem("consultPrice", this.expertP.registerPrice);
      this.$router.push({
        path: "/doctorList",
        query: {
          doctor: data,
        },
      });
    },
    getList() {
      getEvaluatelist(this.params).then((res) => {
        const {
          code,
          result: { total, rows },
        } = res;
        if (code == 200) {
          this.total = Number(total);
          this.evaluateList = rows.map((item) => {
            if (item.scoreAvg != null) {
              item.scoreAvg = item.scoreAvg.toFixed(1);
            } else {
              item.scoreAvg = "0.0";
            }

            return item;
          });
          this.evaluateList = rows || [];
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.list_item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;

  .list_l {
    display: flex;
    align-items: center;

    img {
      width: 33px;
      height: 29px;
      margin-right: 15px;
    }
  }

  .advice_btn {
    width: 100px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    border-radius: 18px;
    background: #fd5151;
    color: #fff;
    cursor: pointer;
  }
}
.evaluate {
  width: 100%;
  margin: 20px 0px;
  padding: 20px;
  border-radius: 10px;
  background: #fff;

  .title {
    display: flex;
    align-items: center;
    font-size: 16px;
    font-weight: 400;

    .image {
      width: 6px;
      height: 18px;
      margin-right: 10px;
      background: #fd5151;
    }
  }
}

.two {
  height: 220px;
}
.parent-box {
  width: 80%;
  margin: 20px auto;
  .ivu-list-item {
    align-items: baseline;
    padding: 10px 10px 36px 50px;
    background: #f9f9f9;
    border-radius: 4px;
    margin-bottom: 10px;
    border: none;
  }
  :deep(.ivu-list-item-extra) {
    width: 70%;
    margin-left: 50px;
  }
  .ivu-list-item-meta {
    flex: inherit;
    width: 20%;
  }
  .grade {
    display: inline-flex;
    align-items: center;
  }
  .child-box {
    width: 100%;
    background: #fff;
    padding: 20px;
    border-radius: 10px;
    margin-top: 10px;
  }
}
</style>
